/*
 * Main.cpp
 *
 *  Created on: May 9, 2017
 *      Author: guoxs
 */
#include "entry/EasyUIContext.h"
#include "uart/UartContext.h"
#include "uart/ProtocolSender.h"
#include "uart/ProtocolParser.h"
#include "uart/ProtocolData.h"
#include "utils/Log.h"
#include "net/WifiManager.h"
#include "http/Network.h"
#include "CommDef.h"

static void queryInfo() {
	typedef struct {
		UINT16 cmdID;
		BYTE deviceID;
	} SInfo;

	SInfo infoTab[] = {
		{ CMDID_POWER, 0 },
		{ CMDID_RUN_MODE, 0 },
		{ CMDID_WIND_SPEED_LEVEL, 0 },
		{ CMDID_WIND_SPEED_LEVEL, 1 },
		{ CMDID_CYCLE_MODEM, 0 },
		{ CMDID_CYCLE_MODEM, 1 },
		{ CMDID_CHILD_LOCK, 0 },
		{ CMDID_UVLIGHT, 0 },
		{ CMDID_UVLIGHT, 1 },
		{ CMDID_ANION, 0 },
		{ CMDID_ANION, 1 },
		{ CMDID_FILTER_REPLACE_TIMER, 0 },
		{ CMDID_FILTER_REPLACE_TIMER, 1 },
		{ CMDID_FILTER_REPLACE_TIMER, 2 },
		{ CMDID_FILTER_REPLACE_TIMER, 3 },
		{ CMDID_TIMMING_TIME_CLOSE, 0 },
		{ CMDID_TIMMING_TIME_OPEN, 0 },
		{ CMDID_NOW_TIME, 0 },
		{ CMDID_BEEP, 0 },
		{ CMDID_ZIGBEE_PAIR, 0 },
		{ CMDID_DEFROST, 0 },
		{ CMDID_HEAT, 0 },
		{ CMDID_HUMIDITY_SET, 0 },
		{ CMDID_PM2_5_SET, 0 },
		{ CMDID_HUMIDIFICATION, 0 },
		{ CMDID_FILTER_REPLACE_TIMER_RESET, 0 },
		{ CMDID_FILTER_REPLACE_TIMER_RESET, 1 },
		{ CMDID_FILTER_REPLACE_TIMER_RESET, 2 },
		{ CMDID_FILTER_REPLACE_TIMER_RESET, 3 },
		{ CMDID_FRESH_AIR_SET, 0 },
		{ CMDID_EXHAUST_SET, 0 },
		{ CMDID_ERROR, 0 },
		{ CMDID_ERROR_CLEAR, 0 },
		{ CMDID_SMART_LINK, 0 },
		{ CMDID_DEVICE_TYPE, 0 },
		{ CMDID_DISPLAY_CTRL, 0 },
		{ CMDID_DISPLAY_ON_TIME, 0 },
		{ CMDID_PM2_5, 0 },
		{ CMDID_CO2, 0 },
		{ CMDID_TVOC, 0 },
		{ CMDID_TEMPERATURE, 0 },
		{ CMDID_TEMPERATURE, 1 },
		{ CMDID_HUMIDITY, 0 },
		{ CMDID_HUMIDITY, 1 },
		{ CMDID_O2, 0 },
		{ CMDID_HCHO, 0 },
		{ CMDID_ESP, 0 },
		{ CMDID_WATER_SHORTAGE, 0 },
		{ CMDID_WIFI_STATE, 0 },
		{ CMDID_ERROR_CODE, 0 }
	};

	int len = TABLESIZE(infoTab);
	BYTE queryFlag = 0xFF;
	for (int i = 0; i < len; ++i) {
		sendProtocol(infoTab[i].cmdID, infoTab[i].deviceID, &queryFlag, 1);
	}
}
Network* netWork;
#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

void onEasyUIInit(EasyUIContext *pContext) {
	LOGD("onInit\n");
	UARTCONTEXT->openUart(UART_NAME, UART_BAUDRATE);
	netWork = new Network();
	// 查询信息
	queryInfo();


	// 初始化童锁密码(目前不做掉电记忆)
	getProtocolData().password = "123456";
}

void onEasyUIDeinit(EasyUIContext *pContext) {
	LOGD("onDestroy\n");
	UARTCONTEXT->closeUart();
}

const char* onStartupApp(EasyUIContext *pContext) {
	return "sliderwindowActivity";
}

#ifdef __cplusplus
}
#endif  /* __cplusplus */
